//
//  ZYtabBarController.m
//  sinaWeiBo_yu
//
//  Created by 振宇陈 on 16/9/5.
//  Copyright © 2016年 振宇陈. All rights reserved.
//

#import "ZYtabBarController.h"
#import "ZYHomeController.h"
#import "ZYMessageController.h"
#import "ZYDiscoverViewController.h"
#import "ZYProfileViewController.h"
#import "ZYTabbar.h"
#import "UIImage+image.h"

@interface ZYtabBarController ()

@end

@implementation ZYtabBarController

//第一次使用这个类或者子类的时候调用
+(void)initialize
{
    //appearance只有一个类遵守UIAppearance，就能获取全局外观
//    获取UITabBarItem所有外观
//    UITabBarItem* item = [UITabBarItem appearance];
    //获取自己类的UITabBarItem的外观
    NSMutableArray* arr = [NSMutableArray array];
    [arr addObject:[ZYtabBarController class]];
    UITabBarItem* item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:arr];
    NSMutableDictionary* dict = [[NSMutableDictionary alloc]init];
    [dict setObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
    [item setTitleTextAttributes:dict forState:UIControlStateSelected];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addControllers];
    ZYTabbar* tabBar = [[ZYTabbar alloc] initWithFrame:self.tabBar.frame];
    [self setValue:tabBar forKey:@"tabBar"];
    
    [tabBar.plusButton addTarget:self action:@selector(didClick) forControlEvents:UIControlEventTouchUpInside];
}


/*Item 就是ios的模型命名规范
 tabBarItem 决定了tabBars上的按钮的内容
 如果通过模型修改控件的颜色，只能通过文本属性（富文本：颜色，字体，空心， 阴影，图文，混排）
 
 IOS 7之后默认UITabBar上面按钮图片颜色渲染成蓝色
 */
-(void) addControllers
{
    [self addChildViewController:[[ZYHomeController alloc]init] :@"首页" :@"tabbar_home"];
    [self addChildViewController:[[ZYMessageController alloc]init] :@"消息" :@"tabbar_message_center"];
    [self addChildViewController:[[ZYProfileViewController alloc]init] :@"发现" :@"tabbar_discover"];
    [self addChildViewController:[[ZYDiscoverViewController alloc]init] :@"我" :@"tabbar_profile"];
}

-(void) addChildViewController:(UIViewController *)childController:(NSString*) title:(NSString*) imageName
{
    UINavigationController* nv = [[UINavigationController alloc] initWithRootViewController:childController];
    childController.title = title;
    childController.tabBarItem.image = [UIImage imageWithOriginalName:imageName];
    NSString* selectName = [NSString stringWithFormat:@"%@_selected",imageName];
    childController.tabBarItem.selectedImage = [UIImage imageWithOriginalName:selectName];
    [self addChildViewController:nv];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)didClick
{
    NSLog(@"%s",__FUNCTION__);
}


@end
